/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PainelUsuario2.java
 *
 * Created on 28/06/2011, 23:35:16
 */
package client;

import client.entidades.User;
import comum.Evento;
import comum.IMsgSource;

/**
 *
 * @author Anderson
 */
public class PainelUsuario extends PainelBase {

//    private User usuario;
    public PainelUsuario(User u) {
        this.setEhUser(true);
        this.parent = u;
        initComponents();
    }

    @Override
    protected void atualiza(Evento evento) {

        if (evento.fonte instanceof IMsgSource && ((IMsgSource) evento.fonte) == parent) {

            if (evento.fonte instanceof User) {

                if (evento.fonte instanceof User && evento.arg instanceof String) {
                    String linha = (String) evento.arg;
                    this.addLinhaTexto(linha);
                    this.pisca();
                }

            }
        }

//
//        if (evento.fonte instanceof User && ((User) evento.fonte) == this.usuario) {
//            if (evento.arg instanceof String) {
//                String linha = "<" + getUsuario().getNick() + "> " + (String) evento.arg;
//                this.conversa.append(linha);
//                this.pisca();
//            }
//        }

    }

    @Override
    protected String getPainelName() {
        return getUsuario().getStringName();
    }

    public User getUsuario() {
        return (User) parent;
    }

    protected PainelBase getInstanciaPainel() {
        return (PainelBase) parent;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.JTextField entrada = this.entrada;
        jScrollPane1 = new javax.swing.JScrollPane();
        javax.swing.JTextArea conversa = this.conversa;

        jScrollPane1.setViewportView(conversa);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 830, Short.MAX_VALUE)
            .addComponent(entrada, javax.swing.GroupLayout.DEFAULT_SIZE, 830, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(entrada, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
